package com.yunze.web.controller.yunze.install;

import com.alibaba.fastjson.JSON;
import com.yunze.common.utils.ServletUtils;
import com.yunze.common.utils.ip.IpUtils;
import com.yunze.common.utils.yunze.AesEncryptUtil;
import com.yunze.system.service.yunze.install.YzInstallEquipmentService;
import com.yunze.web.core.config.MyBaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 设备管理
 * @author liuhang
 * @date 2022-6-17
 * */

@Api("设备管理")
@RestController
@RequestMapping("/yunze/equipment")
public class YzInstallEquipmentController extends MyBaseController {

    @Autowired
    private YzInstallEquipmentService yzInstallEquipmentService;

    /**
     * 执行 设备管理 列表
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:list')")
    @PostMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
    public String SynFlow(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.PstrMap(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:list  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("设备管理[列表] 操作失败！");
    }


    /**
     * 新增查询对应的详细地址
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:selAdd')")
    @PostMapping(value = "/selAdd", produces = {"application/json;charset=UTF-8"})
    public String SelAdd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.selAdd(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:selAdd  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("详细地址 操作失败！");
    }

    /**
     * 查询dept_id 下的建筑物
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:selBuilding')")
    @PostMapping(value = "/selBuilding", produces = {"application/json;charset=UTF-8"})
    public String SleBuildingAdd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.selBuilding(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:selBuilding  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("详细地址 操作失败！");
    }

    /**
     * 查询建筑物楼层
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:selFllor')")
    @PostMapping(value = "/selFllor", produces = {"application/json;charset=UTF-8"})
    public String SleSleFloorAdd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.selFllor(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:selFllor  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("查询建筑物楼层 操作失败！");
    }


    /**
     * 查询接警联系人
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:sleAlarm')")
    @PostMapping(value = "/sleAlarm", produces = {"application/json;charset=UTF-8"})
    public String SlesleAlarmAdd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.sleAlarm(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:sleAlarm  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("查询接警联系人 操作失败！");
    }


    /**
     * 新增安装点
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:add')")
    @PostMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public String AddEquipment(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.add(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:add  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("新增安装点 操作失败！");
    }


    /**
     * 查询住户资料
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:equipment:household')")
    @PostMapping(value = "/household", produces = {"application/json;charset=UTF-8"})
    public String SleHouseholdAdd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallEquipmentService.household(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:equipment:household  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("查询住户资料 操作失败！");
    }

}
